import { HttpMethod } from '@/services/types';
import { request } from '@/api/request';

/**
 * GET /cart 分类列表
 * @param options
 */
export async function resCartList(
  options?: { [key: string]: any },
) {
  return request<API.CartStruct[]>('/cart', {
    method: HttpMethod.GET,
    ...(options || {}),
  });
}



/**
 * Delete /cart 移除购物车
 * @param params
 * @param options
 */
export async function resDeleteCart(
  params: API.CartParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/cart', {
    method: HttpMethod.DELETE,
    data: params,
    ...(options || {}),
  });
}

/**
 * POST /cart 添加购物车
 * @param params
 * @param options
 */
export async function resAddCart(
  params: API.AddCartParams,
  options?: { [key: string]: any },
) {
  return request<R<API.CartStruct>>('/cart', {
    method: HttpMethod.POST,
    data: params,
    ...(options || {}),
  });
}

/**
 * PUT /cart/:id 修改购物车数量
 * @param id
 * @param params
 * @param options
 */
export async function resChangeCartNum(
  id: number,
  params: API.ChangeCartParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/cart/' + id, {
    method: HttpMethod.PUT,
    data: params,
    ...(options || {}),
  });
}

/**
 * PATCH /cart/checked 修改购物车选中
 * @param params
 * @param options
 */
export async function resCartCheck(
  params: API.CartParams,
  options?: { [key: string]: any },
) {
  return request<R<null>>('/cart/checked', {
    method: HttpMethod.PATCH,
    data:params,
    ...(options || {}),
  });
}
